<?php

/**
 * @author Tan-Tan
 * @package SeoPortal
 * @subpackage Server
 */
class AnalyzeSiteActivity extends Ezer_SynchronousActivity
{
	public function execute(array $args)
	{
		$this->log("Executing Analyze Site Activity");
		
		$siteId = $args[CaseManager::VAR_SITE_ID];
		$reportId = $args[CaseManager::VAR_REPORT_ID];
			
		$site = SeoSitePeer::retrieveByPK($siteId);
		if(!$site)
			return false;
			
		$url = SeoUrlPeer::retrieveByPK($site->getUrlId());
		if(!$url)
			return false;
		
		$ranks = LogicManager::getRanks($url->getFullUrl());
		foreach($ranks as $rank)
		{
			$rank->setSiteId($siteId);
			$rank->setReportId($reportId);
			$rank->save();
		}
		
		$backLinks = LogicManager::getBackLinks($url->getFullUrl());
		foreach($backLinks as $backLink)
		{
			$backLink->setSiteId($siteId);
			$backLink->setReportId($reportId);
			$backLink->save();
		}
		 
		return true;
	}
}
